import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/3/6 9:31
 * @description 动态规划，用两个数组left , right保存i左边和右边符合条件的数目，然后遍历统计都符合条件的
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] se = {5,3,3,3,5,6,2};
        solution.goodDaysToRobBank(se, 2);
    }
    public List<Integer> goodDaysToRobBank(int[] security, int time) {
        List<Integer> ans = new ArrayList<>();
        int n = security.length;
        if (time == 0) {
            for (int i = 0; i < n; i++) {
                ans.add(i);
            }
            return ans;
        }
        // left 代表 i 下标的数左边有多少个非递增的，right 代表 i下标的数右边有多少个非递减的
        int[] left = new int[n], right = new int[n];
        for (int i = 1; i < n; i++) {
            if (security[i] <= security[i-1]) {
                left[i] = left[i-1] + 1;
            }
            if (security[n-i-1] <= security[n-i]) {
                right[n-i-1] = right[n-i] + 1;
            }
        }
        // 遍历，查看左右两边至少有time天符合条件
        for (int i = time; i < n - time; i++) {
            if (left[i] >= time && right[i] >= time) {
                ans.add(i);
            }
        }
        return ans;

    }
}
